package com.sihuatech.coreagent.core.communication.entity;

import java.util.ArrayList;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.CaseInsensitiveMap;
import org.apache.commons.httpclient.Header;

public class RequestSendResult {

	private int responseCode = -1;
	private byte[] responseBodyStream;
	private String responseBodyString;
	
	private Map<String, List<String>> responseHeaders = new CaseInsensitiveMap();
	
	public int getResponseCode() {
		return responseCode;
	}
	public void setResponseCode(int responseCode) {
		this.responseCode = responseCode;
	}
	public byte[] getResponseBodyStream() {
		return responseBodyStream;
	}
	public void setResponseBodyStream(byte[] responseBodyStream) {
		this.responseBodyStream = responseBodyStream;
	}	
	public String getResponseBodyString() {
		return responseBodyString;
	}
	public void setResponseBodyString(String responseBodyString) {
		this.responseBodyString = responseBodyString;
	}
	
	public boolean containsHeader(String headerName) {
		return responseHeaders.containsKey(headerName);
	}
	
	@SuppressWarnings("unchecked")
	public List<Header> getHeaders() {
		List<Header> headers=new ArrayList<Header>();
		if(responseHeaders!=null){
			for(Map.Entry<String, List<String>> e:responseHeaders.entrySet()){
				if(e.getValue()!=null){
					for(String v:e.getValue()){
						Header header=new Header(e.getKey(), v);
						headers.add(header);
					}
				}
			}
		}
		return headers;		
	}
	
	
	@SuppressWarnings("unchecked")
	public List<String> getHeaders(String headerName) {
		if(responseHeaders.containsKey(headerName)) {
			return (List<String>)responseHeaders.get(headerName);
		} else {
			return null;
		}		
	}
	
	@SuppressWarnings("unchecked")
	public void addHeader(String headerName,String headerValue) {
		List<String> list = null;
		if(responseHeaders.containsKey(headerName)) {
			list = responseHeaders.get(headerName);
		} else {
			list = new ArrayList<String>();
			responseHeaders.put(headerName, list);
		}
		list.add(headerValue);
	}
}
